package com.tkk.monitoring.analyze;

import com.tkk.monitoring.analyze.http.Request;
import io.netty.handler.codec.http.HttpHeaders;

import java.util.HashMap;
import java.util.Map;

/**
 * author: Tkk
 * date: 2015/7/8
 */
public class AnalyzeTarget {

    private String protocol;

    private String host;

    private int port;

    private String path;

    private String method;

    private HttpHeaders headers;

    private String type;

    private HashMap<String, Object> getParam;

    private String postBody;

    private HashMap<String, Object> postParam;

    public String getPostBody() {
        return postBody;
    }

    public void setPostBody(String postBody) {
        this.postBody = postBody;
    }

    public HashMap<String, Object> getPostParam() {
        return postParam;
    }

    public void setPostParam(HashMap<String, Object> postParam) {
        this.postParam = postParam;
    }


    public HashMap<String, Object> getGetParam() {
        return getParam;
    }

    public void setGetParam(HashMap<String, Object> getParam) {
        this.getParam = getParam;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public HttpHeaders getHeaders() {
        return headers;
    }

    public void setHeaders(HttpHeaders headers) {
        this.headers = headers;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    /**
     * @return
     */
    public String getUrl() {
        return Request.toURL(this.getUri(), this.getGetParam());
    }

    /**
     * @return
     */
    public String getUri() {
        return String.format("%s://%s:%s%s", getProtocol(), getHost(), getPort(), getPath());
    }

    /**
     * @return
     */
    public String getSite() {
        return String.format("%s://%s:%s", getProtocol(), getHost(), getPort());
    }

    /**
     * 是否有参数
     *
     * @return
     */
    public boolean hasParam() {
        Map getParam = getGetParam();
        Map postParam = getPostParam();
        if ((getParam != null && getParam.size() == 0) || (postParam != null && postParam.size() == 0) || (getParam == null && postParam == null)) {
            return false;
        } else {
            return true;
        }
    }
}
